﻿using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.Notify;
using ManagementApi.Models.System.TableLog;
using ManagementApi.Mvc;
using ManagementApi.Mvc.ApplicationContexts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules;
using Modules.BankSpecialAccount;
using Modules.BankSpecialAccount.Entitys;
using Modules.Notify;
using Modules.Payroll;
using Modules.Person;
using Modules.Project;
using Modules.Reports;
using PmSoft.Exceptions;
using PmSoft.Logging;

namespace ManagementApi.Controllers.ManagerPannel;

/// <summary>
/// 首页统计信息接口-项目管理员角色
/// </summary>
[ApiController]
[Route("/api/v1/manager/home")]
[Authorize(Roles = "Manager")]
public class HomeController
{
    private readonly ProjectManagerApplicationContext applicationContext;
    private readonly ILogger logger;
    private readonly ProjectService projectService;
    private readonly SysNotifyService sysNotifyService;
    private readonly SysTableLogService sysTableLogService;
    private readonly IMapper mapper;
    private readonly ProjectGroupMemberService projectGroupMemberService;
    private readonly PersonService personService;
    private readonly PersonCorpContractService personCorpContractService;
    private readonly ReportProjectGroupDaysService reportProjectGroupDaysService;
    private readonly BankSpecialAccountService bankSpecialAccountService;
    private readonly BankSpecialAccountStatisticService bankSpecialAccountStatisticService;
    private readonly ProjectGuaranteePaymentService projectGuaranteePaymentService;
    private readonly ReportProjectMonthService reportProjectMonthService;

    /// <summary>
    /// </summary>
    /// <param name="applicationContext"></param>
    /// <param name="logger"></param>
    /// <param name="projectService"></param>
    /// <param name="sysNotifyService"></param>
    /// <param name="sysTableLogService"></param>
    public HomeController(ProjectManagerApplicationContext applicationContext, ILogger<HomeController> logger, ProjectService projectService,
        SysNotifyService sysNotifyService, SysTableLogService sysTableLogService, IMapper mapper, ProjectGroupMemberService projectGroupMemberService, PersonService personService, PersonCorpContractService personCorpContractService, ReportProjectGroupDaysService reportProjectGroupDaysService, BankSpecialAccountService bankSpecialAccountService, BankSpecialAccountStatisticService bankSpecialAccountStatisticService, ProjectGuaranteePaymentService projectGuaranteePaymentService, ReportProjectMonthService reportProjectMonthService)
    {
        this.applicationContext = applicationContext;
        this.logger = logger;
        this.projectService = projectService;
        this.sysNotifyService = sysNotifyService;
        this.sysTableLogService = sysTableLogService;
        this.mapper = mapper;
        this.projectGroupMemberService = projectGroupMemberService;
        this.personService = personService;
        this.personCorpContractService = personCorpContractService;
        this.reportProjectGroupDaysService = reportProjectGroupDaysService;
        this.bankSpecialAccountService = bankSpecialAccountService;
        this.bankSpecialAccountStatisticService = bankSpecialAccountStatisticService;
        this.projectGuaranteePaymentService = projectGuaranteePaymentService;
        this.reportProjectMonthService = reportProjectMonthService;
    }

    /// <summary>
    /// 首页统计
    /// </summary>
    /// <returns></returns>
    [HttpGet("home_statistic")]
    public ApiResult<HomeStatisticDto> GetHomeStatistic()
    {
        var statistic = projectService.GetHomeStatistic();
        return ApiResult<HomeStatisticDto>.Success(statistic.AsDto(applicationContext));
    }
}